package com.pcl;

import lombok.extern.slf4j.Slf4j;

import java.io.*;

/**
 *
 * 3.文件的操作  -- txt文本读取
 *
 * @author 潘春龙
 * @title: ProjectThree
 * @projectName learn-git-testing
 * @description: TODO
 * @date 2022/2/17
 */
@Slf4j
public class ProjectThree {

  /**
   *
   * 读取.txt文件及内容
   *
   * */
  public static String readFile(File file) {
    StringBuilder result = new StringBuilder();
    try {
      BufferedReader br = new BufferedReader(new FileReader(file));
      String s = null;
      while((s = br.readLine())!=null){
        result.append(System.lineSeparator()+s);
      }
      br.close();
    } catch (Exception e) {
      log.info("文件夹读取出错！",e);
    }
    return  result.toString();
  }

  public static void main(String[] args) {
    File file = new File("C:\\Users\\brains\\Desktop\\a.txt");
    log.info("文件夹内容为："+readFile(file));
  }
}
